package com.euq.mapper;

import com.euq.entity.Menu;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MenuMapper {
    @Select("select * from menu")
    List<Menu> listAll();
    @Delete("delete from menu where id = #{id}")
    void delete(Long id);
    @Select("select * from menu where id = #{id}")
    Menu findById(Long id);
    @Delete("delete from menu where pcodes like CONCAT('%', #{code}, '%')")
    void deleteSubMenu(String code);
    @Select("select * from menu where code=#{code}")
    Menu findByCode(String code);
    @Insert({"INSERT INTO menu (create_by, create_time, modify_by, modify_time, code, component, hidden, icon, isMenu, isOpen, levels, name, num, pcode, pcodes, tips, url)",
            "VALUES (1, now(), 1, now(), #{code}, #{component}, #{hidden}, #{icon}, #{isMenu}, #{isOpen}, #{levels}, #{name}, #{num}, #{pcode}, #{pcodes}, #{tips}, #{url})"
    })
    void insert(Menu menu);
    @Update({"UPDATE menu SET",
            "create_by = 1,",
            "create_time = now(),",
            "modify_by = 1,",
            "modify_time = now(),",
            "code = #{code},",
            "component = #{component},",
            "hidden = #{hidden},",
            "icon = #{icon},",
            "isMenu = #{isMenu},",
            "isOpen = #{isOpen},",
            "levels = #{levels},",
            "name = #{name},",
            "num = #{num},",
            "pcode = #{pcode},",
            "pcodes = #{pcodes},",
            "tips = #{tips},",
            "url = #{url}",
            "WHERE id = #{id}"})
    void update(Menu menu);
}
